package org.lili.performance.chapter8;

/**
 * @author lili
 * @description ${DESCRIPTION}
 * @create 2018-03-03 下午3:43
 * @since
 **/
public class SimpleExample {

    private long runTest(int iterations) {
        long startTime = System.nanoTime();
        // ......  testing ....
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long elapsedTime = System.nanoTime();
        return (elapsedTime - startTime) / iterations;
    }

    public static void main(String[] args) {
        int warmUpCycles = 1000000;
        int testCycles = 50000000;
        SimpleExample se = new SimpleExample();
        System.out.println("Warming up benchmark....");
        long nanosPerIteration = se.runTest(warmUpCycles);
        System.out.println("Done warming up benchmark....");
        System.out.println("Entering measurement interval...");
        nanosPerIteration = se.runTest(testCycles);
        System.out.println("Measurement interval done.");
        System.out.println("Nanoseconds per iteration :" + nanosPerIteration);
    }
}
